package com.parseword1;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;

public class WordTest{
	
	public static String get(String path)throws IOException{
		FileInputStream in = new FileInputStream(path);
		byte[] buf = new byte[in.available()];
		in.read(buf);
		String ngs = new String(buf,Charset.forName("GBK"));
		
		in.close();
		return ngs;
	}
	public static void main(String[] args) throws Exception {
		WordSensitiveHandler handler = new WordSensitiveHandler();// 中文词汇处理
		WordNodes wns = new WordNodes();
		// 获得词库
		StringBuilder ngs = new StringBuilder();
		ngs.append(get("/Users/zhangxingyu/project/敏感词库/百度敏感词/百度过滤词.txt")).append("\n");
		ngs.append(get("/Users/zhangxingyu/project/敏感词库/百度敏感词/百度敏感词.txt"));
		String[] texts = ngs.toString().split("\n");
		for (String text : texts) {
			text = text.replace("\r", "");
			if(!text.trim().isEmpty()){
				wns.add(text, handler);
			}
		}
		System.out.println("词库数量："+texts.length);
		// 输入携带敏感词的内容
		String text = "颠覆hfsdfdsfsbbdk江泽民sjfkdsjfhjkdsfhjsd老哈哈yy通讯录傻b，胡锦涛-hellofuck";
		System.out.println(wns.exec(text,text));
		// 测试效率
		int size = 100000;	
		long time = System.currentTimeMillis();
		for (int i = 0; i < size; i++) {
			 wns.exec(text,text);
		}
		time = System.currentTimeMillis() - time;
		System.out.println("调用次数 "+size+" ,总时间 "+time+" ms");
	}

	
}
